Skip to content

docs: event properties without jQuery, Template.instance() after await, flush timing, Web Components - #541

Open
dupontbertrand wants to merge 1 commit into
meteor:release-3.1.0from
dupontbertrand:docs/web-apis-notes
Open

dupontbertrand wants to merge 1 commit into
meteor:release-3.1.0from
dupontbertrand:docs/web-apis-notes

Conversation

@dupontbertrand

Copy link
Copy Markdown
Collaborator

Summary

Four additions to the docs, coming out of a test pass of the browser APIs listed in the MDN Web API index (149 groups) against the head of release-3.1.0, on both DOM backends, in a PWA. None of them is a Blaze bug: they are behaviours an app developer runs into and that the docs did not state.

Changes

  • migrations.md, "Remove jQuery". jQuery does not copy properties such as dataTransfer, deltaY, clipboardData, inputType, animationName, newState or command onto its event object, so with jQuery they were only reachable through event.originalEvent. With the native backend they are on event itself and event.originalEvent is undefined. The breaking note now says so, with the form that works on both backends.

  • api/templates.md, Template.instance(). In an async helper, callback or event handler, Template.instance() returns null after the first await, because the current instance is only tracked for the synchronous part of the call. The entry now says to capture the instance first (second argument of event handlers, this in callbacks), with an example.

  • guide/understanding-blaze.md, new section "Flushing before the browser looks at the DOM". Blaze updates the DOM at flush time, not when a reactive value changes. APIs that expect the DOM to be updated when their callback returns, like document.startViewTransition(callback), see no change and animate nothing unless the callback ends with Tracker.flush(). The section explains the timing and shows the pattern.

  • guide/reusable-components.md, new section "Web Components". Custom elements render, upgrade and dispatch events as expected, but Blaze only writes attributes, which are strings, so a component that takes structured data through a JavaScript property cannot get it from the template. The section states this and shows the Blaze way: set the property from an autorun in onRendered(), which stays reactive. No change in the core: nobody asked for property binding in ten years and the pattern is three lines.

Verification

Each behaviour was checked in the browser (Chrome 157 on Linux, Chrome 124 on Android) with the native and the jQuery backend, on an app built from meteor create --pwa. Markdown only. npm run docs:build (VitePress) passes and the four pages render as expected; the mustache shown in prose uses <code v-pre> like the rest of the site.

…ponents

Four behaviours met while testing the MDN Web API index against Blaze
3.1 on both backends, stated nowhere in the docs:

- without jQuery, `dataTransfer`, `deltaY`, `clipboardData`, `inputType`
  and similar are on `event` itself, `event.originalEvent` is undefined;
- `Template.instance()` returns null after the first `await` of an async
  helper, callback or event handler;
- the DOM is updated at flush time, so a View Transition callback must
  end with `Tracker.flush()` to animate anything.
- a custom element that takes structured data through a property gets a
  string attribute from the template; set the property from an autorun in
  onRendered() instead.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant